feat(cloudflare): Auto-instrument Durable Object classes#22437
Merged
JPeer264 merged 1 commit intoJul 22, 2026
Merged
Conversation
Contributor
size-limit report 📦
|
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-withsentry
branch
from
July 21, 2026 15:25
e43f7dc to
f03fae8
Compare
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-durableobject
branch
from
July 21, 2026 15:25
1d8ee57 to
6fd1b77
Compare
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-withsentry
branch
from
July 22, 2026 06:04
f03fae8 to
9ecc3e9
Compare
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-durableobject
branch
from
July 22, 2026 06:04
6fd1b77 to
bd69bda
Compare
JPeer264
marked this pull request as ready for review
July 22, 2026 06:07
JPeer264
requested review from
andreiborza,
isaacs and
timfish
and removed request for
a team
July 22, 2026 06:07
timfish
approved these changes
Jul 22, 2026
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-withsentry
branch
from
July 22, 2026 11:05
9ecc3e9 to
367a3a1
Compare
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-durableobject
branch
from
July 22, 2026 11:05
bd69bda to
1ec169c
Compare
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-withsentry
branch
2 times, most recently
from
July 22, 2026 11:25
2596deb to
e8621d5
Compare
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-durableobject
branch
from
July 22, 2026 11:27
1ec169c to
4d31356
Compare
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-withsentry
branch
2 times, most recently
from
July 22, 2026 12:55
4b801b3 to
b1f7bf1
Compare
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-durableobject
branch
from
July 22, 2026 12:56
4d31356 to
c95ffbb
Compare
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-withsentry
branch
from
July 22, 2026 13:13
b1f7bf1 to
ca8e556
Compare
Extend the auto-instrument transform to wrap exported Durable Object classes
(those named in the wrangler `durable_objects` bindings) with
`instrumentDurableObjectWithSentry`, alongside the existing default-export
`withSentry` wrapping.
Handles the inline (`export class MyDO {}`) and specifier
(`class MyDO {}` … `export { MyDO }` / `export { Foo as MyDO }`) forms, leaves
classes already wrapped manually untouched, and warns about configured classes
it can't find in the entry (e.g. re-exports from another module, which can't be
wrapped in place).
Adds a `vite-autoinstrument/durableobject` integration suite: a worker whose
default handler and `Counter` Durable Object are both left unwrapped and wrapped
at build time via the Vite plugin.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
JPeer264
force-pushed
the
jp/cloudflare-auto-instrument-durableobject
branch
from
July 22, 2026 13:13
c95ffbb to
4a5d06f
Compare
Comment on lines
+278
to
+279
| const localClass = localName ? state.topLevelClasses.get(localName) : undefined; | ||
| if (!localName || !localClass?.id) return; |
Contributor
There was a problem hiding this comment.
Bug: Auto-instrumentation fails for Durable Object classes that are defined with an inline export and then re-exported with an alias.
Severity: HIGH
Suggested Fix
Update the collectTopLevelClasses function to traverse ExportNamedDeclaration nodes. This will allow it to discover and collect class declarations that are part of an inline export (e.g., export class Foo {}), making them available for subsequent wrapping logic when an alias is used.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/cloudflare/src/vite/transform.ts#L278-L279
Potential issue: The auto-instrumentation logic fails to wrap a Durable Object class
under specific conditions. When a class is defined with an inline export (e.g., `export
class Foo {}`) and then re-exported with an alias (e.g., `export { Foo as MyDO }`), the
system fails to instrument it. The `collectTopLevelClasses` function does not recognize
inline-exported classes, so it cannot find the original class definition (`Foo`) when
processing the aliased export (`MyDO`). This results in the class not being wrapped and
a misleading warning being issued, preventing the feature from working for this common
code pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extend the auto-instrument transform to wrap exported Durable Object classes (those named in the wrangler
durable_objectsbindings) withinstrumentDurableObjectWithSentry, alongside the existing default-exportwithSentrywrapping.Handles the inline (
export class MyDO {}) and specifier (class MyDO {}…export { MyDO }/export { Foo as MyDO }) forms, leaves classes already wrapped manually untouched, and warns about configured classes it can't find in the entry (e.g. re-exports from another module, which can't be wrapped in place).Adds a
vite-autoinstrument/durableobjectintegration suite: a worker whose default handler andCounterDurable Object are both left unwrapped and wrapped at build time via the Vite plugin.I also added tons of integration tests with couple of gotchas (the majority of additions are actually just tests)